package cn.sciento.farm.devicemanager.api.jsonrpc.impl;

import cn.sciento.farm.devicemanager.api.jsonrpc.AlarmPersonJsonApi;
import cn.sciento.farm.devicemanager.common.constant.ResultConstant;
import cn.sciento.farm.devicemanager.dao.entity.DevCamera;
import cn.sciento.farm.devicemanager.dao.entity.ResAlarmPerson;
import cn.sciento.farm.devicemanager.dao.model.ResponseMessage;
import cn.sciento.farm.devicemanager.service.AlarmPersonService;
import com.googlecode.jsonrpc4j.JsonRpcService;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.sciento.farm.devicemanager.common.util.ReturnUtil.getReturnMap;

@Service
@AutoJsonRpcServiceImpl
public class AlarmPersonJsonApiImpl implements AlarmPersonJsonApi {

    @Autowired
    AlarmPersonService alarmPersonService;


    @Override
    public ResponseMessage create(ResAlarmPerson resAlarmPerson) {
        if(StringUtils.isEmpty(resAlarmPerson.getName())
        || StringUtils.isEmpty(resAlarmPerson.getPhone())){
            return getReturnMap(ResultConstant.NULL_PARAMETER);
        }
        int count  = alarmPersonService.create(resAlarmPerson);
        return getReturnMap(ResultConstant.SUCCESS,count);
    }

    @Override
    public ResponseMessage update(ResAlarmPerson resAlarmPerson) {
        int count = alarmPersonService.updateById(resAlarmPerson);
        return getReturnMap(ResultConstant.SUCCESS,count);
    }

    @Override
    public ResponseMessage delete(Long id) {
        int count = alarmPersonService.deleteById(id);
        return getReturnMap(ResultConstant.SUCCESS,count);
    }

    @Override
    public ResponseMessage list(Integer areaId) {
        List<ResAlarmPerson> cameraList = alarmPersonService.getByAreaId(areaId);
        return getReturnMap(ResultConstant.SUCCESS,cameraList);
    }

    @Override
    public ResponseMessage get(Long id) {
        ResAlarmPerson resAlarmPerson = alarmPersonService.getById(id);
        return getReturnMap(ResultConstant.SUCCESS,resAlarmPerson);
    }
}
